import com.sun.org.apache.xpath.internal.operations.String;
import org.apache.zookeeper.*;

import java.util.List;
import java.util.concurrent.CountDownLatch;

public class GetNodeData {

    private static CountDownLatch countDownLatch = new CountDownLatch(1);

    private static ZooKeeper zooKeeper;

    public void process(WatchedEvent watchedEvent) {

        if(watchedEvent.getType() == Watcher.Event.EventType.NodeChildrenChanged){
            try {
                List<java.lang.String> children = zooKeeper.getChildren("/test", true);
            } catch (KeeperException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }


        if(watchedEvent.getState() == Watcher.Event.KeeperState.SyncConnected){
            try {
                getNodeData1();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

    private void getNodeData1() {
        try {

            byte[] data = zooKeeper.getData("/test", false, null);

            System.out.println(new java.lang.String(data));
        } catch (KeeperException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

    private void getChildrens(){
        try {
            List<java.lang.String> children = zooKeeper.getChildren("/test", true);

        } catch (KeeperException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception{
        zooKeeper = new ZooKeeper("localhost:2181", 5000, new ZookeeperSession());
        Thread.sleep(Integer.MAX_VALUE);
    }



}
